//滚屏
var flag = true;     //是否阻止鼠标滚轮
var rollflag = true;    //自动滚动还是点击滚动
$(document).bind('mousewheel DOMMouseScroll', function(e) {
    return flag;
});

//滚动事件
for (var i = 0; i < $('.containers').length; i++) {
        $('.containers').eq(i).waypoint({
            handler: function(direction) {
                if (!rollflag) {
                    return;
                }
                var timer;
                var that = $(this);
                var num = that.attr('data-num');
                clearTimeout(timer);
                timer = setTimeout(function() {
                    if (direction == 'down') {
                        $('.fixed-slide').fadeIn();
                        if (that.offset()) {
                            flag = false;
                            $('html, body').stop().animate({
                                    'scrollTop': that.offset().top
                                },
                                1000,
                                function() {
                                    flag = true;
                                });
                        };
                        $('.fixed-slide').find('li a').removeClass('active');
                        $('.fixed-slide').find('li').eq(num - 2).find('a').addClass('active');
                    }
                })
            },
            enabled: rollflag,
            offset: '100%'
        });

        //向上滚动事件
        $('.containers').eq(i).waypoint({
            handler: function(direction) {
                if (!rollflag) return;
                var that = $(this);
                var num = that.attr('data-num');
                if (direction == 'up') {
                    if (that.prev().offset()) {
                        $('.fixed-slide').find('li a').removeClass('active');
                        $('.fixed-slide').find('li').eq(num - 3).find('a').addClass('active');
                    }
                }
            },
            enabled: rollflag,
            offset: '100%'
        });
};

//右侧导航
$('.fixed-slide li a').on('click', function() {
    var id = $(this).attr('href');
    rollflag = false;
    $('.fixed-slide').find('li a').removeClass('active');
    $(this).addClass('active');
    $('body,html').stop().animate({
        'scrollTop': $(id).offset().top
    }, 1000, function() {
        rollflag = true;
    });
});

$('#platform-des').waypoint(function(direction) {
    if (direction == 'down') {
        $('.platform-des').find('li').fadeIn(4000);
    }
}, { offset: 377});

 j = 0;
function time2() {
    j ++;
    if (j < 10) {
        setTimeout('time2()', 50);
        $('#num2').html(j);
    }
}
var k = 0;
function time3() {
    k ++;
    if (k < 7) {
        setTimeout('time3()', 50);
        $('#num3').html(k);
    }
}
$('#advantage-des').waypoint(function(direction) {
    if (direction == 'down') {
        time2();
        time3();
    }
}, { offset: 435});


$('.data-icon').waypoint(function(direction) {
    var that = $(this);
    if (direction == 'down') {
        that.addClass('move').css('opacity', 1)
    }
}, { offset:  443});
